package com.qian.ddj.web.controller;

import com.qian.api.ddj.model.Certification;
import com.qian.api.ddj.model.CertificationCondition;
import com.qian.api.ddj.service.ICertificationService;
import com.yaowk.api.common.PageReq;
import com.yaowk.api.common.PageResp;
import com.yaowk.web.system.security.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "实名认证")
@RequestMapping("/ddj/certification")
public class CertificationController {
    @Autowired
    private ICertificationService certificationService;

    @PostMapping("/save")
    @ApiOperation("保存或者修改实名认证")
    public void save(Certification certification) {
        certification.setUserId(SecurityUtils.getUserId());
        certificationService.save(certification);
    }

    @GetMapping("/queryCertificationById/{id}")
    @ApiOperation("通过ID查找认证")
    public Certification queryCertificationById(@PathVariable Integer id) {
        Certification certification = certificationService.findById(id);
        return certification;
    }

    @GetMapping("/queryAllCertification")
    @ApiOperation("查询所有列表")
    public PageResp<Certification> queryAllCertification(PageReq pageReq) {
        PageResp<Certification> pageResp = certificationService.findAll(pageReq);
        return pageResp;
    }

    @GetMapping("/deleteCertificationById/{id}")
    @ApiOperation("通过ID删除列表")
    public void deleteCertificationById(@PathVariable Integer id) {
        certificationService.deleteById(id);
    }

    @PostMapping("/update")
    @ApiOperation("更改用户信息审核状态")
    public void update(Certification certification, Byte status) {
        certification.setCertificationCondition(status);
        certificationService.update(certification);
    }

    @GetMapping("/queryCertificationConditionByUserId")
    @ApiOperation("获取用户个人审核信息")
    public CertificationCondition queryCertificationConditionByUserId(){

       return certificationService.QueryStatusByUserId(SecurityUtils.getUserId());
    }
}
